<template>
	<view>
		<!-- 搜索栏 -->
		<view class="search-my">
			<my-search @click="gotoSearch"></my-search>
		</view>
		<!-- 轮播图 -->
		<swiper class="swiper" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" circular="true">
			<swiper-item v-for="(item,i) in swiperList" :key="i">
				<navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id='+item.goods_id">
					<image :src="item.image_src" class="image"></image>
				</navigator>
			</swiper-item>
		</swiper>
		<!-- 分类导航 -->
		<view class="nav-list">
			<view class="nav-item" v-for="(item,i) in navList" :key="i" @click="navClickHandler(item)">
				<image :src="item.image_src" mode="aspectFill"></image>
			</view>
		</view>
		<!-- 楼层区域 -->
		<view class="floor-list">
			<!-- 楼层的item项 -->
			<view class="floor-item" v-for="(item,i) in floorList" :key="i">
				<!-- 楼层标题 -->
				<image :src="item.floor_title.image_src"></image>
				
				<!-- 楼层图片区域 -->
				<view class="floor-img-box">
					<!-- 左边图片的区域 -->
					<navigator class="floor-img-left" :url="item.product_list[0].url">
						<image :src="item.product_list[0].image_src" :style="{width: item.product_list[0].image_width + 'rpx'}" mode="widthFix"></image>
					</navigator> 
					<!-- 右边图片的区域 -->
					<view class="floor-img-right">
						<navigator class="floor-img-right-item" v-for="(list,a) in item.product_list" :key="a" :url="list.url" v-if="a!=0">
							<image :src="list.image_src" mode="widthFix" :style="{width: list.image_width + 'rpx'}"></image>
						</navigator>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import tabbar from '@/mixins/tabbar-badge.js'
	export default {
		mixins: [tabbar],
		data() {
			return {
				//轮播图数据
				swiperList: [],
				//分类导航的数据
				navList: [],
				//楼层数据
				floorList: []
			};
		},
		onLoad() {
			this.getSwiperList()
			this.getNavList()
			this.getFloorList()
		},
		methods: {
			//获取轮播图数据
			async getSwiperList(){
				const {data:res} = await uni.$http.get('/api/public/v1/home/swiperdata')
				if(res.meta.status != 200){
					return uni.$showMessage()
				}
				this.swiperList = res.message
				uni.$showSuccess()
			},
			//获取分类导航的数据
			async getNavList(){
				const {data:res} = await uni.$http.get('/api/public/v1/home/catitems')
				if(res.meta.status != 200){
					return uni.$showMessage()
				}
				this.navList = res.message
				uni.$showSuccess()
			},
			//获取楼层数据
			async getFloorList(){
				const {data:res} = await uni.$http.get('/api/public/v1/home/floordata')
				if(res.meta.status != 200){
					return uni.$showMessage()
				}
				//
				res.message.forEach(item =>{
					item.product_list.forEach(list =>{
						list.url="/subpkg/goods_list/goods_list?"+list.navigator_url.split('?')[1]
					})
				})
				
				this.floorList = res.message
				uni.$showSuccess()
			},
			//跳转分类导航页
			navClickHandler(item) {
				if(item.name == "分类"){
					uni.switchTab({
						url:"/pages/cate/cate"
					})
				}
			},
			gotoSearch(){
				uni.navigateTo({
					url:"/subpkg/search/search"
				})
			}
		}
	}
</script>

<style lang="scss">
.swiper{
	height: 330rpx;
	.swiper-item,
	.image{
		height: 100%;
		width: 100%;
	}
}
.nav-list{
	display: flex;
	width: 100%;
	//使布局伸缩项目均匀分布在行中，两端有一半大小的空间。
	justify-content: space-around;
	image{
		height: 140rpx;
		width: 128rpx;
	}
}
.floor-list{
	image{
		width: 100%;
		height: 60rpx;
		display: flex;
	}
}
.floor-img-box{
	justify-content:space-around;
	display: flex;
	padding-left: 10rpx;
	.floor-img-left{
	}
	.floor-img-right{
		display: flex;
		flex-wrap: wrap;
	}
}
//设置吸顶效果
.search-my{
	position: sticky;
	top: 0;
	z-index: 999;
}
</style>
